package com.genesis.web.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.genesis.mall.common.PmsProductPage;
import com.genesis.mall.common.Result;
import com.genesis.mall.entity.PmsProduct;
import com.genesis.mall.service.IPmsProductService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商品信息 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-08-01
 */
@RestController
@RequestMapping("/product")
public class PmsProductController {

    @Autowired
    private IPmsProductService pmsProductService;

    /**
     * 新品新增商品展示
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("/list")
    public Result<PmsProductPage<PmsProduct>>list(Long pageNum,Long pageSize,String keyword){
        Page<PmsProduct> pageInfo = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<PmsProduct> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(keyword),PmsProduct::getName,keyword);
        queryWrapper.orderByDesc(PmsProduct::getOriginalPrice);
        pmsProductService.page(pageInfo,queryWrapper);

        PmsProductPage<PmsProduct> productPage = new PmsProductPage<>();
        BeanUtils.copyProperties(pageInfo,productPage);

        return Result.success(productPage);
    }





}
